package com.atguigu.gmall.order.delay;

import lombok.Data;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

@Data
public class OrderDelayTask implements Delayed {        // 延迟任务类

    private Long orderId ;
    private Long delayTime ;

    public OrderDelayTask(Long orderId , Long delayTime)  {
        this.orderId = orderId ;
        this.delayTime = System.currentTimeMillis() + delayTime ;
    }

    @Override
    public long getDelay(TimeUnit unit) {
        return delayTime - System.currentTimeMillis();
    }

    @Override
    public int compareTo(Delayed o) {
        return (int)(this.getDelay(TimeUnit.MILLISECONDS) - o.getDelay(TimeUnit.MILLISECONDS));
    }
}
